function [data_out] = XFFT_2(data_in)
%基2-FFT
%   Detailed explanation goes here
    %% 数组补零
    N = length(data_in);
    N_bit = ceil(log2(N));
    N_ceil = 2^N_bit;
    if(N<N_ceil)
        fft_in = [data_in,zeros(1,N_ceil-N)];
    else
        fft_in = data_in;
    end
    %% 序列倒序
    fft_data = zeros(1,N_ceil);
    %方法1:简单的位操作
    for K = 0:2^N_bit-1
        fft_data(K+1) = fft_in(bin2dec(flip(dec2bin(K,N_bit)))+1);
    end
    %方法2:使用位翻转函数
    K = 0:2^N_bit-1;
    fft_data = fft_in(bitrevorder(K)+1);
    %% 基2旋转因子
    Base_2 = 2;
    matrix1 = zeros(Base_2,Base_2);
    for K = 1:Base_2
        for L = 1:Base_2
            m = mod((K-1)*(L-1),Base_2);
            matrix1(K,L) = W_mN(m,Base_2);
        end
    end
    %%
    xfft_r = zeros(1,N_ceil);
    for series = 0:N_bit-1
        %蝶形运算矩阵
        [ADD] = matrix_add2(N_bit,series);
        ADD(1:2,:) = ADD(1:2,:)+1;
        %矩阵计算
        for M=1:length(ADD(1,:))
            if(series==0)
                data_matrix = [fft_data(ADD(1,M));fft_data(ADD(2,M))];
            else
                data_matrix = [xfft_r(ADD(1,M));xfft_r(ADD(2,M))];
            end
            matrix2 = zeros(Base_2,Base_2);
            for T=1:Base_2
                matrix2(T,T) = W_mN(ADD(Base_2+1,M)*(T-1),2^(series+1));
            end
            matrix_r1 = matrix1*matrix2*data_matrix;
            xfft_r(ADD(1,M)) = matrix_r1(1);
            xfft_r(ADD(2,M)) = matrix_r1(2);
        end
    end
    %%
    data_out = xfft_r;
end